linear regression
Tutorials
Linear Regression with Python | Connor Johnson
http://connor-johnson.com/2014/02/18/linear-regression-with-python/
#pandas #statsmodels #scikit-learn
hr.icon
numpy
numpy.polyfit
https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html
code:python
np.polyfit(x,y,deg=1)
hr.icon
scipy
scipy.stats.linregress
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html
scipy.optimize.curve_fit
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
code:python
from scipy import optimize
# Define a model function
def model_func(x, a0, a1):
return a0 + (a1*x)
param_opt, param_cov = optimize.curve_fit(model_func, x_data, y_data)
a0 = param_opt0 # a0 is the intercept in y = a0 + a1*x
a1 = param_opt1 # a1 is the slope in y = a0 + a1*x
hr.icon
pandas
examples
pandas pandas で 回帰分析 - tetsunosukeのnotebook
http://tetsunosuke.hatenablog.com/entry/2014/02/23/175754
hr.icon
statsmodels
Statsmodels Examples
https://www.statsmodels.org/stable/examples/index.html#regression
Linear Regression
https://www.statsmodels.org/stable/regression.html
Fitting models using R-style formulas
https://www.statsmodels.org/stable/example_formulas.html?highlight=statsmodels%20formula%20api
Examples
code:python
import pandas as pd
from statsmodels.formula.api import ols
df = pd.DataFrame(dict(x_column=x_data, y_column=y_data))
# Pass data and formula into ols(), use and .fit() the model to the data
model_fit = ols(formula="y_column ~ x_column", data=df).fit()
# Use .predict(df) to get y_model values, then over-plot y_data with y_model
y_model = model_fit.predict(df)
# Extract the a0, a1 values from model_fit.params
a0 = model_fit.params'Intercept'
a1 = model_fit.params'x_column'
uncertainty_in_intercept = model_fit.bse'Intercept'
uncertainty_in_slope = model_fit.bse'x_column
Regression beteeen the Kushimoto-Uragami sea-level difference and Kuroshio-Path latitude (on Google Colab)
https://colab.research.google.com/drive/1QBcpWTwGiEpWAqz84d0XhchmPq9NpmMA
hr.icon
scikit-learn
sklearn.linear_model.LinearRegression
https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html
Examples
code:python
from sklearn.linear_model import LinearRegression
# Initialize a general model
model = LinearRegression(fit_intercept=True)
# Load and shape the data
x_data = x_raw.reshape(len(y_raw),1)
y_data = y_raw.reshape(len(y_raw),1)
# Fit the model to the data
model_fit = model.fit(x_data, y_data)
# Extract the linear model parameters
intercept = model.intercept_0
slope = model.coef_0,0
# Extract the linear model parameters
intercept = model.intercept_0
slope = model.coef_0,0
MetPy Mondays `#182​​ - Linear Regression with Scikit-Learn - Basic Machine Learning : Unidata Developer's Blog
This week we explore some machine learning basics on a new MetPyMonday!
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-182-linear-regression
sklearn.linear_model.Ridge
https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Ridge.html
Tutorials
一般化線形モデルのラッソとリッジでの推定量算出・予測 - Qiita
https://qiita.com/ynakayama/items/cc1b1c9e90beef7a19c5
Paid tutorials
Machine Learning for Time Series Data in Python | DataCamp
https://www.datacamp.com/courses/machine-learning-for-time-series-data-in-python
hr.icon
Patsy: Describing statistical models in Python using symbolic formulas
hr.icon
See also
curve fitting
Cross decomposition